<template>
  <div class="wrapper">
    <swiper ref="mySwiper" :options="swiperOptions">
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" />
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props: {
    list: Array
  },
  data() {
    return {
      swiperOptions: {
        pagination: {
          el: ".swiper-pagination"
        },
        loop: true,
        autoplay: {
          delay: 3000,
          stopOnLastSlide: false,
          disableOnInteraction: true,
          reverseDirection: false,
          waitForTransition: true
        }
      }
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    }
  },
  mounted() {
    console.log("Current Swiper instance object", this.swiper);
    this.swiper.slideTo(1, 1000, false);
  }
};
</script>

<style lang="stylus" scoped>
.wrapper /deep/ .swiper-pagination-bullet-active
  background: #fff
.wrapper /deep/ .swiper-pagination-bullets
  bottom: 90px
.wrapper
  width: 100%
  height: 0
  overflow: hidden
  padding-bottom: 56.25%
  // 以上4行代码等价于 width: 100%; height: 56.25vw
  background: #eee
  .swiper-img
    width: 100%
</style>
